Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Get active element in document when body contenteditable="true"

I'm testing the below in edge browser but I'm ultimately trying to get this to work inside an activex webbrowser contol on a form "shellExplorer.2"

I'm just trying to do this natively so I don't want jquery solution.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>JS Bin</title>
  <script type="text/javascript">
    function docode() {    
      console.log(document.activeElement.tagName);
    }
  </script>
</head>
<body onclick="docode();" contentEditable="true">
    <div tabindex=1>Here</div>
    <div>Nothing here</div>
    <div contenteditable>Something here</div>
    <table>
        <tr>
          <td> test text </td> <td> test 2</td>   
        </tr>
    </table>  
  </body>
</html>

I have the above html. Ultimately I need to know which element is clicked on so I can find out if the element is inside a table for example. (my old code worked and I walk up the parentnodes until I hit a table or a body tag.

All I seem to get is "BODY". Sometimes I might be lucky and get a DIV for the div with a tabindex.

I have tried the following function and that just returns "undefined"

    function docode() {    
      var ovar = window.getSelection();
      var orange = ovar.getRangeAt(0);
      console.log(orange.tagname);
    }

The getSelection() and getRangeAt(0) used to work but it seems microsoft have changed something in the control.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!